<?php
/**
 * Course Class Model
 *
 * Copyright 2012
 * @date 21-April-2012
 * @author 
 * @version 0.0.1
 **/
class City extends AppModel {
/**
 * Name
 *
 * @var string
 */
    public $name = 'City';
    public $belongsTo = array(
        'Country'=>array(
            'className'=>'Country',
            'foreignKey'=>'country_id'
        )
    );
    
    public static function get_name($id){
        $country = ClassRegistry::init('City');
        $country->id = $id;
        return $country->field('name');
    }
    
    public function check_exist($country_id,$name){
        $country = $this->find('first',array('conditions'=>array('City.name'=>$name,'City.country_id'=>$country_id)));
        if(!empty($country)){
            return $country['City']['id'];
        }
        return 0;
    }
}